package com.smartstate.EnvironmentMonitor.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * <p>@Description: No Description</p>
 * <p>@Author 陈永杰</p>
 * <p>@Date: 2022/8/17</p>
 * <p>@Time: 23:31</p>
 * <p>@version 1.0 <p>
 */
public class IBeanUtils {

    /**
     * 转换对象
     *
     * @param sources        源对象list
     * @param targetSupplier 目标对象供应方
     * @param <S>            源对象类型
     * @param <T>            目标对象类型
     * @return 目标对象list
     */
    public static <S, T> List<T> convertListTo(List<S> sources, Supplier<T> targetSupplier) {
        if (null == sources || null == targetSupplier) {
            return null;
        }

        List<T> list = new ArrayList<>(sources.size());
        for (S source : sources) {
            T target = targetSupplier.get();
            BeanUtils.copyProperties(source, target);
            list.add(target);
        }

        return list;
    }

}